package com.registration.util;

import cn.dev33.satoken.stp.SaTokenInfo;

public class JsonResponse {
    private int code;
    private String msg;
    private Object data;
    SaTokenInfo saTokenInfo;

    public static JsonResponse success(Object data) {
        JsonResponse response = new JsonResponse();
        response.setCode(0);
        response.setMsg("success");
        response.setData(data);
        return response;
    }

    public static JsonResponse success(Object data, String message) {
        JsonResponse response = new JsonResponse();
        response.setCode(0);
        response.setMsg(message);
        response.setData(data);
        return response;
    }

    // 失败静态方法
    public static JsonResponse fail(String message) {
        JsonResponse response = new JsonResponse();
        response.setCode(1);
        response.setMsg(message);
        return response;
    }

    public static JsonResponse fail(int code, String message) {
        JsonResponse response = new JsonResponse();
        response.setCode(code);
        response.setMsg(message);
        return response;
    }

    public static JsonResponse loginOut() {
        JsonResponse response = new JsonResponse();
        response.setCode(401);
        response.setMsg("未登录");
        return response;
    }


    @Override
    public String toString() {
        return "JsonResponse{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public SaTokenInfo getSaTokenInfo() {
        return saTokenInfo;
    }

    public void setSaTokenInfo(SaTokenInfo saTokenInfo) {
        this.saTokenInfo = saTokenInfo;
    }
}
